home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / MetalworksPrefs.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  221 lines

  1. /*
  2.  * @(#)MetalworksPrefs.java    1.2 98/02/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. import java.awt.*;
  22. import java.awt.event.*;
  23. import java.beans.*;
  24. import com.sun.java.swing.*;
  25. import com.sun.java.swing.border.*;
  26. import com.sun.java.swing.plaf.metal.*;
  27.  
  28.  
  29. /**
  30.   * This is dialog which allows users to choose preferences
  31.   *
  32.  * @version 1.2 02/05/98
  33.   * @author Steve Wilson
  34.   */
  35. public class MetalworksPrefs extends JDialog {
  36.  
  37.     public MetalworksPrefs(JFrame f) {
  38.         super(f, "Preferences", true);
  39.     JPanel container = new JPanel();
  40.     container.setLayout( new BorderLayout() );
  41.  
  42.      JTabbedPane tabs = new JTabbedPane();
  43.     JPanel filters = buildFilterPanel();
  44.     JPanel conn = buildConnectingPanel();
  45.     tabs.addTab( "Filters", null, filters );
  46.     tabs.addTab( "Connecting", null, conn );
  47.  
  48.  
  49.     JPanel buttonPanel = new JPanel();
  50.     buttonPanel.setLayout ( new FlowLayout(FlowLayout.RIGHT) );
  51.     JButton cancel = new JButton("Cancel");
  52.     cancel.addActionListener(new ActionListener() {
  53.                            public void actionPerformed(ActionEvent e) {
  54.                    CancelPressed();
  55.                    }});
  56.     buttonPanel.add( cancel );
  57.     JButton ok = new JButton("OK");
  58.     ok.addActionListener(new ActionListener() {
  59.                            public void actionPerformed(ActionEvent e) {
  60.                    OKPressed();
  61.                    }});
  62.     buttonPanel.add( ok );
  63.     getRootPane().setDefaultButton(ok);
  64.  
  65.     container.add(tabs, BorderLayout.CENTER);
  66.     container.add(buttonPanel, BorderLayout.SOUTH);
  67.     getContentPane().add(container);
  68.     pack();
  69.     centerDialog();
  70.     UIManager.addPropertyChangeListener(new UISwitchListener(container));
  71.     }
  72.  
  73.     public JPanel buildFilterPanel() {
  74.     JPanel filters = new JPanel();
  75.     filters.setLayout( new GridLayout(1, 0) );
  76.  
  77.     JPanel spamPanel = new JPanel();
  78.  
  79.     spamPanel.setLayout(new ColumnLayout());
  80.     spamPanel.setBorder( new TitledBorder("Spam") );
  81.     ButtonGroup spamGroup = new ButtonGroup();
  82.     JRadioButton file = new JRadioButton("File in Spam Folder");
  83.     JRadioButton delete = new JRadioButton("Auto Delete");
  84.     JRadioButton bomb = new JRadioButton("Reverse Mail-Bomb");
  85.     spamGroup.add(file);
  86.     spamGroup.add(delete);
  87.     spamGroup.add(bomb);   
  88.     spamPanel.add(file);
  89.     spamPanel.add(delete);
  90.     spamPanel.add(bomb);  
  91.     file.setSelected(true);
  92.     filters.add(spamPanel);
  93.     
  94.     JPanel autoRespond = new JPanel();
  95.     autoRespond.setLayout(new ColumnLayout());
  96.     autoRespond.setBorder( new TitledBorder("Auto Response") );
  97.  
  98.     ButtonGroup respondGroup = new ButtonGroup();
  99.     JRadioButton none = new JRadioButton("None");
  100.     JRadioButton vaca = new JRadioButton("Send Vacation Message");
  101.     JRadioButton thx = new JRadioButton("Send Thank You Message");
  102.  
  103.     respondGroup.add(none);
  104.     respondGroup.add(vaca);
  105.     respondGroup.add(thx);
  106.  
  107.     autoRespond.add(none);
  108.     autoRespond.add(vaca);
  109.     autoRespond.add(thx);
  110.  
  111.     none.setSelected(true);
  112.     filters.add(autoRespond);
  113.  
  114.     return filters;
  115.     }
  116.  
  117.     public JPanel buildConnectingPanel() {
  118.     JPanel connectPanel = new JPanel();
  119.     connectPanel.setLayout( new ColumnLayout() );
  120.  
  121.     JPanel protoPanel = new JPanel();
  122.     JLabel protoLabel = new JLabel ("Protocol");
  123.     JComboBox protocol = new JComboBox();
  124.     protocol.addItem("SMTP");
  125.     protocol.addItem("IMAP");
  126.     protocol.addItem("Other...");
  127.     protoPanel.add(protoLabel);
  128.     protoPanel.add(protocol);
  129.  
  130.     JPanel attachmentPanel = new JPanel();
  131.     JLabel attachmentLabel = new JLabel ("Attachments");
  132.     JComboBox attach = new JComboBox();
  133.     attach.addItem("Download Always");
  134.     attach.addItem("Ask size > 1 Meg");
  135.     attach.addItem("Ask size > 5 Meg");
  136.     attach.addItem("Ask Always");
  137.     attachmentPanel.add(attachmentLabel);
  138.     attachmentPanel.add(attach);
  139.  
  140.     JCheckBox autoConn = new JCheckBox("Auto Connect");
  141.     JCheckBox compress = new JCheckBox("Use Compression");
  142.     autoConn.setSelected( true );
  143.  
  144.     connectPanel.add(protoPanel);
  145.     connectPanel.add(attachmentPanel);
  146.     connectPanel.add(autoConn);
  147.     connectPanel.add(compress);
  148.     return connectPanel;
  149.     }
  150.  
  151.  
  152.  
  153.     protected void centerDialog() {
  154.         Dimension screenSize = this.getToolkit().getScreenSize();
  155.     Dimension size = this.getSize();
  156.     screenSize.height = screenSize.height/2;
  157.     screenSize.width = screenSize.width/2;
  158.     size.height = size.height/2;
  159.     size.width = size.width/2;
  160.     int y = screenSize.height - size.height;
  161.     int x = screenSize.width - size.width;
  162.     this.setLocation(x,y);
  163.     }
  164.  
  165.     public void CancelPressed() {
  166.         this.setVisible(false);
  167.     }
  168.  
  169.     public void OKPressed() {
  170.         this.setVisible(false);
  171.     }
  172.   
  173. }
  174.  
  175. class ColumnLayout implements LayoutManager {
  176.  
  177.   int xInset = 5;
  178.   int yInset = 5;
  179.   int yGap = 2;
  180.  
  181.   public void addLayoutComponent(String s, Component c) {}
  182.  
  183.   public void layoutContainer(Container c) {
  184.       Insets insets = c.getInsets();
  185.       int height = yInset + insets.top;
  186.       
  187.       Component[] children = c.getComponents();
  188.       Dimension compSize = null;
  189.       for (int i = 0; i < children.length; i++) {
  190.       compSize = children[i].getPreferredSize();
  191.       children[i].setSize(compSize.width, compSize.height);
  192.       children[i].setLocation( xInset + insets.left, height);
  193.       height += compSize.height + yGap;
  194.       }
  195.  
  196.   }
  197.  
  198.   public Dimension minimumLayoutSize(Container c) {
  199.       Insets insets = c.getInsets();
  200.       int height = yInset + insets.top;
  201.       int width = 0 + insets.left + insets.right;
  202.       
  203.       Component[] children = c.getComponents();
  204.       Dimension compSize = null;
  205.       for (int i = 0; i < children.length; i++) {
  206.       compSize = children[i].getPreferredSize();
  207.       height += compSize.height + yGap;
  208.       width = Math.max(width, compSize.width + insets.left + insets.right + xInset*2);
  209.       }
  210.       height += insets.bottom;
  211.       return new Dimension( width, height);
  212.   }
  213.   
  214.   public Dimension preferredLayoutSize(Container c) {
  215.       return minimumLayoutSize(c);
  216.   }
  217.    
  218.   public void removeLayoutComponent(Component c) {}
  219.  
  220. }
  221.